package com.yanqu.road.server.cmd.activity.entername;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.entername.EnterNameActivityMgr;
import com.yanqu.road.server.protocol.ChannelProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_ENTER_NAME_GROUP_RANK, desc = "地区排行")
public class EnterNameGroupRankCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        EnterNameProto.EnterNameGroupRankReqMsg reqMsg = EnterNameProto.EnterNameGroupRankReqMsg.parseFrom(packet.getBytes());
        if(!EnterNameActivityMgr.activityInShowTime(reqMsg.getActivityId())){
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        EnterNameProto.ChannelEnterNameGroupRankReqMsg.Builder channelReq = EnterNameProto.ChannelEnterNameGroupRankReqMsg.newBuilder();
        channelReq.setActivityId(reqMsg.getActivityId());
        channelReq.setUserKey(EnterNameActivityMgr.buildKeyMsg(player.getUserId()));
        if(reqMsg.hasNoData()){
            channelReq.setNoData(reqMsg.getNoData());
        }
        if(reqMsg.hasAllGroup()) {
            channelReq.setAllGroup(reqMsg.getAllGroup());
        }
        if(reqMsg.hasType()){
            channelReq.setType(reqMsg.getType());
        }
        player.sendChannelPacket(ChannelProtocol.N_ENTER_NAME_GROUP_RANK, channelReq);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_ENTER_NAME_GROUP_RANK, EnterNameProto.EnterNameGroupRankRespMsg.newBuilder().setRet(ret));
        }
    }
}
